import axiosIns from '@/plugins/axios';

// 获取值班安排列表
export async function fetchDutyList(startDate?: string, endDate?: string) {
  const options = {
    method: 'GET',
    url: `/api/duty/list.do`,
    params: {
      ...(startDate && { startDate }),
      ...(endDate && { endDate })
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return axiosIns.request(options);
}

// 添加值班安排
export async function addDuty(dutyData: {
  user_id: number;
  role: string;
  start_time: string;
  end_time: string;
  location?: string;
}) {
  const options = {
    method: 'POST',
    url: `/api/duty/add.do`,
    data: dutyData,
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return axiosIns.request(options);
}

// 更新值班安排
export async function updateDuty(dutyId: number, dutyData: {
  user_id: number;
  role: string;
  start_time: string;
  end_time: string;
  location?: string;
}) {
  const options = {
    method: 'POST',
    url: `/api/duty/update.do`,
    data: {
      id: dutyId,
      ...dutyData
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return axiosIns.request(options);
}

// 删除值班安排
export async function deleteDuty(dutyId: number) {
  const options = {
    method: 'POST',
    url: `/api/duty/delete.do`,
    data: {
      id: dutyId
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return axiosIns.request(options);
}

// 批量添加值班安排
export async function batchAddDuty(dutiesData: Array<{
  user_id: number;
  role: string;
  start_time: string;
  end_time: string;
  location?: string;
}>) {
  const options = {
    method: 'POST',
    url: `/api/duty/batch-add.do`,
    data: dutiesData,
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return axiosIns.request(options);
} 